package cn.wawi.dao.sys;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import cn.wawi.common.annotation.MybatisRepository;
import cn.wawi.dao.BaseDao;
import cn.wawi.entity.sys.Resources;

@MybatisRepository
public interface ResourcesDao<T extends Resources> extends BaseDao<T> {

	/**
	 * 获取用户所拥有的菜单或权限
	 * @param userId 用户id
	 * @param type 1菜单 2权限 0全部
	 * @return 权限或菜单列表
	 */
	List<Resources> getUserPermission(@Param("userId") int userId,@Param("type") int type);
	
	/**
	 * 获取角色所拥有的权限
	 * @param roleId 角色id
	 * @return 资源列表
	 */
	@Select("SELECT resources_id id from sys_role_resources where role_id=#{roleId}")
	List<Resources> getRoleResource(int roleId);

	@Delete("delete from sys_role_resources where role_id=#{roleId}")
	void deleteRoleResources(Integer roleId);

	@Insert("insert into sys_role_resources values(#{roleId},#{resourcesId})")
	void saveRoleResources(@Param("roleId")Integer roleId, @Param("resourcesId")int resourcesId);
}

